package com.bsoft.gol.hbs.service.impl;

import com.bsoft.gol.hbs.dao.PcnSignRemindParamDAO;
import com.bsoft.gol.hbs.utils.CommonUtils;
import ctd.account.UserRoleToken;
import ctd.spring.boot.annotation.SsdevService;
import ctd.util.annotation.RpcService;
import org.atag.util.common.RedisUtil;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import pcn.service.sign.PcnSignRemindParamService;
import pcn.sign.PcnSignRemindParam;
import pcn.vo.sign.PcnSignRemindModifyVo;

import java.util.List;

/**
 * Created by kongqing on 2017/7/5.
 */
@SsdevService("pcnSignRemindParamService")
public class PcnSignRemindParamServiceImpl implements PcnSignRemindParamService {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(PcnSignRemindParamService.class);
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private PcnSignRemindParamDAO pcnSignRemindParamDAO;

    /**
     * 测试redis zcj 2019年9月19日21:48:27
     *
     * @param key
     */
    @RpcService
    public void testRedis(String key) {
        if (redisUtil.setnx(key, String.valueOf(System.currentTimeMillis() + 100 * 1000), 100)) {
            LOGGER.info("开始执行创建  key：" + key);
        } else {
            String expirationTime = redisUtil.get(key);
            LOGGER.info("key：" + key + "  value：" + expirationTime);
            Long time = Long.valueOf(expirationTime) - System.currentTimeMillis();
            LOGGER.info("您已经保存了此key，请等待" + time / 1000 + "秒过期后再试");
        }
    }

    @Override
    @RpcService
    public PcnSignRemindModifyVo modify(PcnSignRemindParam pcnSignRemindParam) {
        PcnSignRemindModifyVo result = new PcnSignRemindModifyVo();
        pcnSignRemindParam.setTenantId(UserRoleToken.getCurrent().getTenantId());
        if (CommonUtils.isNotEmpty(pcnSignRemindParam.getParamId()) && pcnSignRemindParam.getParamId().intValue() > 0) {
            pcnSignRemindParamDAO.update(pcnSignRemindParam);
            result.setParamId(pcnSignRemindParam.getParamId());
        } else {
            PcnSignRemindParam signRemindParam = pcnSignRemindParamDAO.save(pcnSignRemindParam);
            result.setParamId(signRemindParam.getParamId());

        }
        return result;
    }

    @Override
    @RpcService
    public PcnSignRemindParam detail(Integer paramId) {
        PcnSignRemindParam pcnSignRemindParam = pcnSignRemindParamDAO.get(paramId);
        return pcnSignRemindParam;
    }

    @Override
    @RpcService
    public List<PcnSignRemindParam> findAll() {
        List<PcnSignRemindParam> paramList = pcnSignRemindParamDAO.findPcnSignRemindParams();
        return paramList;
    }

    @Override
    @RpcService
    public void delete(Integer paramId) {
        pcnSignRemindParamDAO.remove(paramId);
    }

    @Override
    public void sendRenewTask() {

    }

    /**
     * @description: 根据名称查询配置列表
     * @date: 2023/12/6 16:54
     * @param: tenantId
     * @param: paramName
     * @param: isEnable
     * @return: java.util.List<pcn.sign.PcnSignRemindParam>
     */
    @Override
    public List<PcnSignRemindParam> findPcnSignRemindParamByParamName(String tenantId, String paramName, String isEnable) {

        List<PcnSignRemindParam> pcnSignRemindParams = pcnSignRemindParamDAO.findPcnSignRemindParamByParamName(tenantId, paramName, isEnable);
        return pcnSignRemindParams;
    }

}
